spring cloud將spring boot服務注冊到Eureka Server上的方法
開篇:
我們將前面的springboot整合H2內存數據庫,實現(xiàn)單元測試與數據庫無關性提供的Restful服務注冊到spring cloud的Eureka Server上。
一、引入Eureka的Client
</dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
二、添加配置文件
# spring boot服務注冊到Eureka Server上的應用名稱 spring.application.name=springboot-h2 eureka.instance.prefer-ip-address=true # Eureka Server注冊服務的地址 eureka.client.service-url.defaultZone=http://localhost:8761/eureka
三、開啟Eureka Client支持
package com.chhliu.springboot.h2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class SpringbootH2Application { public static void main(String[] args) { SpringApplication.run(SpringbootH2Application.class, args); } }
四、啟動spring boot服務并驗證
通過上面幾個步驟,說明我們已經將spring boot的服務注冊到了Eureka Server上了!
五、可能出現(xiàn)的問題
如果在服務注冊的過程中,發(fā)現(xiàn)Connection refused異常,如下:
有可能是hosts文件中沒有加入如下映射關系
127.0.0.1 loaclhost
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
springboot中@ConfigurationProperties無效果的解決方法
本文主要介紹了springboot中@ConfigurationProperties無效果,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2024-06-06Elasticsearch中store field與non-store field的區(qū)別說明
這篇文章主要介紹了Elasticsearch中store field與non-store field的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07Spring?Cloud?Alibaba?Nacos服務治理平臺服務注冊、RestTemplate實現(xiàn)微服務之間訪
這篇文章主要介紹了Spring?Cloud?Alibaba:Nacos服務治理平臺,服務注冊、RestTemplate實現(xiàn)微服務之間訪問,負載均衡訪問,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06